package com.anysoft.user;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.anysoft.MentorConst;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.anysoft.HostConstant;
import com.anysoft.R;
import com.anysoft.adapter.TaxPayerAdapter;
import com.anysoft.base.BaseActivity;
import com.anysoft.bean.AccountLoginBean;
import com.anysoft.bean.BaseBean;
import com.anysoft.bean.QueryCertificateTypeBean;
import com.anysoft.bean.QueryCountryBean;
import com.anysoft.bean.QueryProfessionBean;
import com.anysoft.bean.QueryTaxProvinceCityBean;
import com.anysoft.bean.QueryUserInfoBean;
import com.anysoft.bean.TaxTaxpayernoInfoRequestsBean;
import com.anysoft.bean.TaxPayerInfo;
import com.anysoft.linstener.OnNextLinstener;
import com.anysoft.me.callback.StringDialogCallback;
import com.anysoft.utils.AESUtils;
import com.anysoft.utils.ActivityUtils;
import com.anysoft.utils.CommonUtil;
import com.anysoft.utils.DisplayUtil;
import com.anysoft.utils.HttpUtils;
import com.anysoft.utils.MentorLogger;
import com.anysoft.utils.ParamUtil;
import com.anysoft.utils.PreferencesUtils;
import com.anysoft.utils.StringUtils;
import com.anysoft.utils.TipPopwindowHelper;
import com.anysoft.view.CustomDividerItemDecoration;
import com.anysoft.view.HWEditText;
import com.anysoft.view.picker.DatePickerView;
import com.anysoft.view.picker.NomarlPickerPopupWindow;
import com.google.gson.Gson;
import com.kyleduo.switchbutton.SwitchButton;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.OnClick;

import static com.anysoft.MentorApplication.context;

/**
 * Created by lty.
 */

public class UserInfoEditActivity extends BaseActivity implements View.OnClickListener {
    LinearLayout activity_user_info_edit_root;
    RecyclerView mRecyclerView;
    Button leftButton;
    TextView title;

    TextView tv_user_name;
    TextView tv_certificates_validity;//证件有效期限
    CheckBox cbox_certificates_validity;//是否长期有效
    HWEditText et_email;//et_email
    RelativeLayout rl_select_occupation;//选择职业
    TextView tv_occupation_name;//职业名称
    HWEditText et_user_info_duty; //职务
    HWEditText et_address;//地址
    HWEditText et_zip_code;//邮编


    //3.07新增 账户是否由他人控制
    SwitchButton sbtn_is_others_control; //是否由他人控制
    LinearLayout ll_others_control_container;
    HWEditText et_others_control_name;
    HWEditText et_control_identity;
    TextView tv_control_identityType;
    ImageView iv_control_identityType;
    TextView tv_control_identity_validity;
    CheckBox cb_control_identity_validity_time;
    HWEditText et_control_cause;
    TextView tv_control_length;

    //3.07新增 实际受益人是否是本人
    SwitchButton sbtn_is_beneficial_owner; //是否本人收益
    LinearLayout ll_beneficial_owner_container;
    HWEditText et_beneficial_owner_name;
    HWEditText et_beneficial_owner_identity;
    TextView tv_beneficial_identityType;
    ImageView iv_beneficial_identityType;
    TextView tv_beneficial_identity_validity;
    CheckBox cb_beneficial_identity_validity_time;
    HWEditText et_beneficial_owner_cause;//受益人说明原因
    TextView tv_beneficial_owner_length;

    //3.07新增 不良记录
    SwitchButton sbtn_is_bad_record; //是否有不良记录
    LinearLayout ll_bad_record_container;
    HWEditText et_bad_record;
    TextView tv_bad_record_length;

    //个人涉税
    LinearLayout ll_tax_layout; //涉税根布局
    //请选择居民身份 声明
    TextView tv_register_step_2_identity_statement;
    ImageView iv_register_step_2_identity_statement;
    //3.0.8新增 红色问号提示
    RelativeLayout rl_tips_flag;
    TextView tv_tips_flag;

    /*3.0.9 改动 现税收居民信息*/
    LinearLayout ll_tax_user_info_layout;
    HWEditText et_tax_surname; //姓
    HWEditText et_tax_name; //名

    /*3.0.9 改动 现居住详细地址*/
    LinearLayout ll_tax_live_address_layout;
    //请选择国家
    RelativeLayout rl_tv_tax_live_address_country_layout;
    TextView tv_tax_live_address_country;
    RelativeLayout rl_tax_live_address_province_layout;
    //请选择省
    TextView tv_tax_live_address_province;
    HWEditText hwet_tax_live_address_province;
    ImageView iv_tax_live_address_province;
    //请选择市
    RelativeLayout rl_tax_live_address_city_layout;
    TextView tv_tax_live_address_city;
    HWEditText hwet_tax_live_address_city;
    ImageView iv_tax_live_address_city;
    /*中文地址*/
    LinearLayout ll_live_chinese_address_container;
    //输入中文地址
    HWEditText et_tax_live_chinese_address;
    //输入拼音地址
    HWEditText et_tax_live_pinyin_address;
    /*英文地址*/
    LinearLayout ll_live_nochinese_address_container;
    //输入英文地址
    HWEditText et_tax_live_english_address;

    /*3.0.9改动 出生地详细地址*/
    LinearLayout ll_tax_birthplace_address_layout;
    //请选择国别
    RelativeLayout rl_tax_birthplace_address_country;
    TextView tv_tax_birthplace_address_country;
    //请选择省
    RelativeLayout rl_tax_birthplace_address_province_layout;
    TextView tv_tax_birthplace_address_province;
    //请输入省
    HWEditText hwet_tax_birthplace_address_province;
    ImageView iv_tax_birthplace_address_province;
    //请选择市
    RelativeLayout rl_tax_birthplace_address_city_layout;
    TextView tv_tax_birthplace_address_city;
    HWEditText hwet_tax_birthplace_address_city;
    ImageView iv_tax_birthplace_address_city;

    //其他纳税人
    TextView tv_other_taxpayer;
    //声明复选框
    CheckBox cb_ident_shengming_info;

    /**
     * 1.性别，2.职业 5:居民身份类型 6：现居地国别 7：出生地国别 8，9，10：为 识别号的 国别1，2，3
     * 11：现居地 省 12 现居地 市
     * 13：出生地 省  14 出生地 市
     */
    private int currentType = 1;
    private boolean provincePopShow = false;
    private int currentPosition;
    private ArrayList<String> list = new ArrayList<>();
    private List<QueryTaxProvinceCityBean.DataBean> taxProvinceList = new ArrayList<>();
    private List<QueryTaxProvinceCityBean.DataBean> taxCityList = new ArrayList<>();
    private boolean cityPopShow = false;
    private List<QueryProfessionBean.DataBean> professionList = new ArrayList<>();
    private NomarlPickerPopupWindow nomarlPickerPopupWindow;
    private int selectPosition = -1;
    private String profession;//所选择的职业代码
    private DatePickerView datePickerView;
    private Map<String, String> paramsModifyUserInfo;//用户信息修改的参数

    //3.0.7新增
    private int datePickerType; //证件有效期选择框类型 100: 开户者证件有效期 101: 账户控制他人证件有效期 102: 受益人他人证件有效期
    private DatePickerView.OnTimeSelectListener mDatePickerSelectLinstener = new DatePickerView
            .OnTimeSelectListener() {
        @Override
        public void onTimeSelect(Date date) {
            switch (datePickerType) {
                case 100:
                    cbox_certificates_validity.setChecked(false);
                    tv_certificates_validity.setText(StringUtils.formatDate(date, StringUtils.SHORT_DATE_FORMAT));
                    break;
                case 101:
                    tv_control_identity_validity.setText(StringUtils.formatDate(date, StringUtils.SHORT_DATE_FORMAT));
                    cb_control_identity_validity_time.setChecked(false);
                    break;
                case 102:
                    tv_beneficial_identity_validity.setText(StringUtils.formatDate(date, StringUtils.SHORT_DATE_FORMAT));
                    cb_beneficial_identity_validity_time.setChecked(false);
                    break;
            }

        }
    };
    private List<QueryCertificateTypeBean.DataBean> identityTypeList = new ArrayList<>(); //他人控制及实际受益人证件类型
    private boolean isFirstComing = true;
    private String occupation; //职务
    private String controllerName;  //控制人姓名
    private String controllerCertType = "0"; //控制人证件类型
    private String controllerCertNo; //控制人证件号
    private String controllerCertValidTerm; //控制人证件有效期
    private String controllerInstruction; //控制人说明

    private String beneficiaryName;  //实际受益人姓名
    private String beneficiaryCertType = "0";  //实际受益证件类型
    private String beneficiaryCertNo;  //实际受益人证件号
    private String beneficiaryCertValidTerm;  //实际受益人证件有效期
    private String beneficiaryInstruction;  //实际受益人说明原因

    private String badCreditRecords;  //有无不良记录
    private int maxTaxpayerSize = 10;
    private TextView tv_tax_ident_num_country;
    private List<TaxPayerInfo> taxPayersContainer = new ArrayList<>(); //展示的集合容器
    private List<TaxPayerInfo> taxPayersTotal = new ArrayList<>(); //集合总大小
    private TaxPayerAdapter taxPayerAdapter;
    private String sZipCode;
    private String sEmail;
    private String sAddress;
    private int showDialogType;
    private AccountLoginBean.DataBean accountLoginData;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info_edit);
        initContentView();
        title.setText("个人资料修改");
        if (mentorApplication != null && mentorApplication.accountLoginBean != null &&
                mentorApplication.accountLoginBean.getData() != null) {
            accountLoginData = mentorApplication.accountLoginBean.getData();
        }
        //3.0.9新增
        initRecyclerViewLayout();
        getCountry(false);
        getTaxType(true);
        getProfession(false);
        getIndentityType(false);
        getTaxProvince(false);
        queryUserInfo();
        cbox_certificates_validity.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    tv_certificates_validity.setText("");
                }
            }
        });
        View borderViews[] = {et_email, et_zip_code, et_address, et_tax_surname,
                et_tax_name, hwet_tax_live_address_province, et_tax_live_chinese_address,
                et_tax_live_pinyin_address, hwet_tax_birthplace_address_city,
                et_beneficial_owner_name, et_beneficial_owner_cause, et_bad_record, et_user_info_duty};
        ParamUtil.clearSelectedBorder(borderViews);
        setOnNextLinstener(new OnNextLinstener() {
            @Override
            public void OnCancelNext() {
                if (showDialogType == 1) {
                    ActivityUtils.gotoUploadIditityCardActivity(UserInfoEditActivity.this, "0", "4");
                } else if (showDialogType == 2) {
                    ActivityUtils.gotoUploadIditityCardActivity(UserInfoEditActivity.this, "0", "104");
                }
            }

            @Override
            public void OnConfirmNext() {
                if (showDialogType == 1) {
                    saveData();
                }
            }

            @Override
            public void OndoConfirm() {

            }
        });
        et_address.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                String etRegisterAddress = et_address.getText().toString();
                if (!hasFocus) {
                    if (!StringUtils.isNullOrEmpty(etRegisterAddress)) {
                        if (etRegisterAddress.length() < 8) {
                            showConfirmAlert(UserInfoEditActivity.this,
                                    getResources().getString(R.string.string_register_step2_address_match1));
                            et_address.setIsSelected(true);
                            et_address.setText("");
                        } else if (!StringUtils.isContainChinese(etRegisterAddress)) {
                            showConfirmAlert(UserInfoEditActivity.this,
                                    getResources().getString(R.string.string_register_step2_address_match2));
                            et_address.setIsSelected(true);
                            et_address.setText("");
                        } else{
                            et_address.setIsSelected(false);
                        }
                    }
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private void initContentView() {
        leftButton = (Button) findViewById(R.id.leftButton);
        title = (TextView) findViewById(R.id.title);
        activity_user_info_edit_root = (LinearLayout) findViewById(R.id.activity_user_info_edit_root);
        mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        leftButton.setOnClickListener(this);
    }

    /**
     * 新增纳税人的容器
     */
    private void initRecyclerViewLayout() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        linearLayoutManager.setAutoMeasureEnabled(true);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.addItemDecoration(new CustomDividerItemDecoration(DisplayUtil.dp2px(this, 10)));
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setNestedScrollingEnabled(false);
        taxPayerAdapter = new TaxPayerAdapter(taxPayersContainer);
        mRecyclerView.setAdapter(taxPayerAdapter);
        taxPayerAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_BOTTOM);
        taxPayerAdapter.addHeaderView(getHeaderView());
        taxPayerAdapter.addFooterView(getFooterView());
        taxPayerAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                TaxPayerInfo adapterItemtem = (TaxPayerInfo) adapter.getItem(position);
                switch (adapterItemtem.getItemType()) {
                    case TaxPayerInfo.TAX_NO_OBTAIN:
                        switch (view.getId()) {
                            case R.id.tv_tax_noobtain_country:
                                tv_tax_ident_num_country = ((TextView) view);
                                currentType = position + 100;
                                currentPosition = 0;
                                initPopList();
                                if (list != null && !list.isEmpty() && list.size() > 0) {
                                    showPicker();
                                } else {
                                    getCountry(true);
                                }
                                break;
                            case R.id.ll_deleate_noobtain_taxpayer:
                                taxPayerAdapter.removeData(position);
                                taxPayersTotal.clear();
                                taxPayersTotal.addAll(taxPayersContainer);
                                break;
                        }
                        break;
                    case TaxPayerInfo.TAX_OBTAIN:
                        switch (view.getId()) {
                            case R.id.tv_tax_obtain_country:
                                tv_tax_ident_num_country = ((TextView) view);
                                currentType = position + 100;
                                currentPosition = 0;
                                initPopList();
                                if (list != null && !list.isEmpty() && list.size() > 0) {
                                    showPicker();
                                } else {
                                    getCountry(true);
                                }
                                break;
                            case R.id.ll_deleate_obtain_taxpayer:
                                taxPayerAdapter.removeData(position);
                                taxPayersTotal.clear();
                                taxPayersTotal.addAll(taxPayersContainer);
                                break;
                        }
                        break;
                }
            }
        });

        taxPayerAdapter.setOnViewCheckedChangeListener(new TaxPayerAdapter.OnViewCheckedChangeListener() {

            @Override
            public void OnCheckedChange(TaxPayerInfo taxPayerInfo, View view, BaseViewHolder helper, boolean isChecked) {
                int position = helper.getAdapterPosition();
                switch (taxPayerInfo.getItemType()) {
                    case TaxPayerInfo.TAX_NO_OBTAIN:
                        switch (view.getId()) {
                            case R.id.sbtn_tax_noobtain:
                                ((SwitchButton) view).setChecked(false);
                                taxPayerInfo.setTaxPayerSwitchStatus(true);
                                taxPayerInfo.setItemType(TaxPayerInfo.TAX_OBTAIN);
                                taxPayerAdapter.notifyItemChanged(position);
                                break;
                        }
                        break;
                    case TaxPayerInfo.TAX_OBTAIN:
                        switch (view.getId()) {
                            case R.id.sbtn_tax_obtain:
                                ((SwitchButton) view).setChecked(true);
                                taxPayerInfo.setTaxPayerSwitchStatus(false);
                                taxPayerInfo.setItemType(TaxPayerInfo.TAX_NO_OBTAIN);
                                taxPayerAdapter.notifyItemChanged(position);
                                break;
                        }
                        break;
                }
            }
        });
    }

    public void clearRecyclerView() {
        taxPayersContainer.clear();
        if (taxPayerAdapter != null) {
            taxPayerAdapter.notifyDataSetChanged();
        }
    }

    @NonNull
    private View getHeaderView() {
        //增加头
        View taxHeaderView = View.inflate(this, R.layout.include_user_info_edit_head_layout, null);
        //初始化基本信息
        initBasicInfoLayout(taxHeaderView);
        //初始化由他人控制
        initAccountControlLayout(taxHeaderView);
        //初始化收益人
        initBeneficialOwnerLayout(taxHeaderView);
        //初始化不良记录
        initBedRecordLayout(taxHeaderView);

        //初始化涉税
        initTaxLayout(taxHeaderView);
        return taxHeaderView;
    }

    @NonNull
    private View getFooterView() {
        //增加尾
        View taxFooterView = View.inflate(this, R.layout.include_register_step_2_footer_layout, null);
        tv_other_taxpayer = (TextView) taxFooterView.findViewById(R.id.tv_other_taxpayer);
        tv_other_taxpayer.setOnClickListener(new FooterViewClickListener());
        Button btn_register_step_2 = (Button) taxFooterView.findViewById(R.id.btn_register_step_2);
        btn_register_step_2.setOnClickListener(new FooterViewClickListener());
        btn_register_step_2.setText("确定");
        cb_ident_shengming_info = (CheckBox) taxFooterView.findViewById(R.id.cb_ident_shengming_info);
        if ("0".equals(mentorApplication.accountLoginBean.getData().getIdentityType())) {
            cb_ident_shengming_info.setClickable(false);
        } else {
            cb_ident_shengming_info.setClickable(true);
        }
        return taxFooterView;
    }

    private void initBasicInfoLayout(View taxHeaderView) {
        tv_user_name = (TextView) taxHeaderView.findViewById(R.id.tv_user_name);
        tv_certificates_validity = (TextView) taxHeaderView.findViewById(R.id.tv_certificates_validity);
        cbox_certificates_validity = (CheckBox) taxHeaderView.findViewById(R.id.cbox_certificates_validity);
        et_email = (HWEditText) taxHeaderView.findViewById(R.id.et_email);
        rl_select_occupation = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_select_occupation);
        tv_occupation_name = (TextView) taxHeaderView.findViewById(R.id.tv_occupation_name);
        et_user_info_duty = (HWEditText) taxHeaderView.findViewById(R.id.et_user_info_duty);
        et_address = (HWEditText) taxHeaderView.findViewById(R.id.et_address);
        et_zip_code = (HWEditText) taxHeaderView.findViewById(R.id.et_zip_code);

        tv_certificates_validity.setOnClickListener(this);
        rl_select_occupation.setOnClickListener(this);
        if ("0".equals(mentorApplication.accountLoginBean.getData().getIdentityType())) {
            cbox_certificates_validity.setClickable(false);
        } else {
            cbox_certificates_validity.setClickable(true);
        }
    }

    /**
     * 初始化涉税布局
     *
     * @param taxHeaderView
     */
    private void initTaxLayout(View taxHeaderView) {
        ll_tax_layout = (LinearLayout) taxHeaderView.findViewById(R.id.ll_tax_layout);
        tv_register_step_2_identity_statement = (TextView) taxHeaderView.findViewById(R.id.tv_register_step_2_identity_statement);
        iv_register_step_2_identity_statement = (ImageView) taxHeaderView.findViewById(R.id.iv_register_step_2_identity_statement);
        rl_tips_flag = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_tips_flag);
        tv_tips_flag = (TextView) taxHeaderView.findViewById(R.id.tv_tips_flag);
        tv_register_step_2_identity_statement.setOnClickListener(this);
        iv_register_step_2_identity_statement.setOnClickListener(this);
        rl_tips_flag.setOnClickListener(this);
        //税收居民
        ll_tax_user_info_layout = (LinearLayout) taxHeaderView.findViewById(R.id.ll_tax_user_info_layout);
        et_tax_surname = (HWEditText) taxHeaderView.findViewById(R.id.et_tax_surname);
        et_tax_name = (HWEditText) taxHeaderView.findViewById(R.id.et_tax_name);

        //现居住详细地址
        ll_tax_live_address_layout = (LinearLayout) taxHeaderView.findViewById(R.id.ll_tax_live_address_layout);
        //国家
        rl_tv_tax_live_address_country_layout = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_tv_tax_live_address_country_layout);
        tv_tax_live_address_country = (TextView) taxHeaderView.findViewById(R.id.tv_tax_live_address_country);
        rl_tv_tax_live_address_country_layout.setOnClickListener(this);
        //省
        rl_tax_live_address_province_layout = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_tax_live_address_province_layout);
        tv_tax_live_address_province = (TextView) taxHeaderView.findViewById(R.id.tv_tax_live_address_province);
        hwet_tax_live_address_province = (HWEditText) taxHeaderView.findViewById(R.id.hwet_tax_live_address_province);
        iv_tax_live_address_province = (ImageView) taxHeaderView.findViewById(R.id.iv_tax_live_address_province);
        rl_tax_live_address_province_layout.setOnClickListener(this);
        //市
        rl_tax_live_address_city_layout = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_tax_live_address_city_layout);
        tv_tax_live_address_city = (TextView) taxHeaderView.findViewById(R.id.tv_tax_live_address_city);
        hwet_tax_live_address_city = (HWEditText) taxHeaderView.findViewById(R.id.hwet_tax_live_address_city);
        iv_tax_live_address_city = (ImageView) taxHeaderView.findViewById(R.id.iv_tax_live_address_city);
        rl_tax_live_address_city_layout.setOnClickListener(this);
        //中文地址
        ll_live_chinese_address_container = (LinearLayout) taxHeaderView.findViewById(R.id.ll_live_chinese_address_container);
        et_tax_live_chinese_address = (HWEditText) taxHeaderView.findViewById(R.id.et_tax_live_chinese_address);
        et_tax_live_pinyin_address = (HWEditText) taxHeaderView.findViewById(R.id.et_tax_live_pinyin_address);
        //非中文地址
        ll_live_nochinese_address_container = (LinearLayout) taxHeaderView.findViewById(R.id.ll_live_nochinese_address_container);
        et_tax_live_english_address = (HWEditText) taxHeaderView.findViewById(R.id.et_tax_live_english_address);

        //出生地详细地址
        ll_tax_birthplace_address_layout = (LinearLayout) taxHeaderView.findViewById(R.id.ll_tax_birthplace_address_layout);
        //国家
        rl_tax_birthplace_address_country = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_tax_birthplace_address_country);
        tv_tax_birthplace_address_country = (TextView) taxHeaderView.findViewById(R.id.tv_tax_birthplace_address_country);
        rl_tax_birthplace_address_country.setOnClickListener(this);
        //省
        rl_tax_birthplace_address_province_layout = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_tax_birthplace_address_province_layout);
        tv_tax_birthplace_address_province = (TextView) taxHeaderView.findViewById(R.id.tv_tax_birthplace_address_province);
        hwet_tax_birthplace_address_province = (HWEditText) taxHeaderView.findViewById(R.id.hwet_tax_birthplace_address_province);
        iv_tax_birthplace_address_province = (ImageView) taxHeaderView.findViewById(R.id.iv_tax_birthplace_address_province);
        rl_tax_birthplace_address_province_layout.setOnClickListener(this);
        //市
        rl_tax_birthplace_address_city_layout = (RelativeLayout) taxHeaderView.findViewById(R.id.rl_tax_birthplace_address_city_layout);
        tv_tax_birthplace_address_city = (TextView) taxHeaderView.findViewById(R.id.tv_tax_birthplace_address_city);
        hwet_tax_birthplace_address_city = (HWEditText) taxHeaderView.findViewById(R.id.hwet_tax_birthplace_address_city);
        iv_tax_birthplace_address_city = (ImageView) taxHeaderView.findViewById(R.id.iv_tax_birthplace_address_city);
        rl_tax_birthplace_address_city_layout.setOnClickListener(this);
        ParamUtil.setEditorNextAction(et_tax_live_english_address);
        ParamUtil.setEditorNextAction(et_tax_live_pinyin_address);
    }

    /**
     * 查询用户信息
     */
    private void queryUserInfo() {
        Map<String, String> params = new HashMap<>();
        params.put("token", mentorApplication.userBean.getToken());
        params.put("fundCustomerNo", mentorApplication.userBean.getFundCustomerNo());
        OkGo.<String>post(HostConstant.QUERY_USER_INFO)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, params))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        parseJson_userinfo(response.body());
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    /**
     * 解析获取得用户个人信息接口返回json数据
     *
     * @param json
     */

    QueryUserInfoBean queryUserInfoBean;

    private void parseJson_userinfo(String json) {

        try {
            queryUserInfoBean = new Gson().fromJson(json, QueryUserInfoBean.class);
        } catch (Exception e) {
            Logger.e(TAG, "Gson解析数据时发生异常");
            showConfirmAlert(this, "提示", "数据解析错误");
            e.printStackTrace();
            return;
        }

        if (!CommonUtil.checkState(this, queryUserInfoBean, json)) {
            return;
        }
        initUserInfo(queryUserInfoBean);
    }

    /**
     * 初始化不良记录的布局
     *
     * @param taxHeaderView
     */
    private void initBedRecordLayout(View taxHeaderView) {
        sbtn_is_bad_record = (SwitchButton) taxHeaderView.findViewById(R.id.sbtn_is_bad_record);
        ll_bad_record_container = (LinearLayout) taxHeaderView.findViewById(R.id.ll_bad_record_container);
        et_bad_record = (HWEditText) taxHeaderView.findViewById(R.id.et_bad_record);
        tv_bad_record_length = (TextView) taxHeaderView.findViewById(R.id.tv_bad_record_length);

        sbtn_is_bad_record.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked) {
                    ll_bad_record_container.setVisibility(View.VISIBLE);
                } else {
                    ll_bad_record_container.setVisibility(View.GONE);
                }
            }
        });
        ParamUtil.setEditorNextAction(et_bad_record);
        et_bad_record.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (!StringUtils.isNullOrEmpty(charSequence.toString()) && charSequence.toString().length() > 0) {
                    if (charSequence.toString().length() > 120) {
                        tv_bad_record_length.setText("120/120字");
                    } else {
                        tv_bad_record_length.setText(charSequence.toString().length() + "/120字");
                    }
                } else {
                    tv_bad_record_length.setText("0/120字");
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }

    /**
     * 初始化受益人布局
     */
    private void initBeneficialOwnerLayout(View taxHeaderView) {
        sbtn_is_beneficial_owner = (SwitchButton) taxHeaderView.findViewById(R.id.sbtn_is_beneficial_owner);
        ll_beneficial_owner_container = (LinearLayout) taxHeaderView.findViewById(R.id.ll_beneficial_owner_container);
        et_beneficial_owner_name = (HWEditText) taxHeaderView.findViewById(R.id.et_beneficial_owner_name);
        et_beneficial_owner_identity = (HWEditText) taxHeaderView.findViewById(R.id.et_beneficial_owner_identity);
        tv_beneficial_identityType = (TextView) taxHeaderView.findViewById(R.id.tv_beneficial_identityType);
        iv_beneficial_identityType = (ImageView) taxHeaderView.findViewById(R.id.iv_beneficial_identityType);
        tv_beneficial_identity_validity = (TextView) taxHeaderView.findViewById(R.id.tv_beneficial_identity_validity);
        cb_beneficial_identity_validity_time = (CheckBox) taxHeaderView.findViewById(R.id.cb_beneficial_identity_validity_time);
        et_beneficial_owner_cause = (HWEditText) taxHeaderView.findViewById(R.id.et_beneficial_owner_cause);
        tv_beneficial_owner_length = (TextView) taxHeaderView.findViewById(R.id.tv_beneficial_owner_length);

        tv_beneficial_identityType.setOnClickListener(this);
        iv_beneficial_identityType.setOnClickListener(this);
        tv_beneficial_identity_validity.setOnClickListener(this);

        sbtn_is_beneficial_owner.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked) {
                    ll_beneficial_owner_container.setVisibility(View.GONE);
                } else {
                    ll_beneficial_owner_container.setVisibility(View.VISIBLE);
                }
            }
        });
        ParamUtil.setEditorNextAction(et_beneficial_owner_cause);
        et_beneficial_owner_cause.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (!StringUtils.isNullOrEmpty(charSequence.toString()) && charSequence.toString().length() > 0) {
                    if (charSequence.toString().length() > 120) {
                        tv_beneficial_owner_length.setText("120/120字");
                    } else {
                        tv_beneficial_owner_length.setText(charSequence.toString().length() + "/120字");
                    }
                } else {
                    tv_beneficial_owner_length.setText("0/120字");
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        cb_beneficial_identity_validity_time.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked) {
                    tv_beneficial_identity_validity.setText("");
                }
            }
        });
    }

    /**
     * 初始化账户是否由他人控制的布局
     */
    private void initAccountControlLayout(View taxHeaderView) {
        sbtn_is_others_control = (SwitchButton) taxHeaderView.findViewById(R.id.sbtn_is_others_control); //控制开关
        ll_others_control_container = (LinearLayout) taxHeaderView.findViewById(R.id.ll_others_control_container);
        et_others_control_name = (HWEditText) taxHeaderView.findViewById(R.id.et_others_control_name); //真实姓名
        tv_control_identityType = (TextView) taxHeaderView.findViewById(R.id.tv_control_identityType); //证件类型
        et_control_identity = (HWEditText) taxHeaderView.findViewById(R.id.et_control_identity); //证件号
        iv_control_identityType = (ImageView) taxHeaderView.findViewById(R.id.iv_control_identityType);
        tv_control_identity_validity = (TextView) taxHeaderView.findViewById(R.id.tv_control_identity_validity);
        cb_control_identity_validity_time = (CheckBox) taxHeaderView.findViewById(R.id.cb_control_identity_validity_time);
        et_control_cause = (HWEditText) taxHeaderView.findViewById(R.id.et_control_cause);
        tv_control_length = (TextView) taxHeaderView.findViewById(R.id.tv_control_length);

        tv_control_identityType.setOnClickListener(this);
        iv_control_identityType.setOnClickListener(this);
        tv_control_identity_validity.setOnClickListener(this);

        sbtn_is_others_control.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked) {
                    ll_others_control_container.setVisibility(View.VISIBLE);
                } else {
                    ll_others_control_container.setVisibility(View.GONE);
                }
            }
        });
        ParamUtil.setEditorNextAction(et_control_cause);
        et_control_cause.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (!StringUtils.isNullOrEmpty(charSequence.toString()) && charSequence.toString().length() > 0) {
                    if (charSequence.toString().length() > 120) {
                        tv_control_length.setText("120/120字");
                    } else {
                        tv_control_length.setText(charSequence.toString().length() + "/120字");
                    }
                } else {
                    tv_control_length.setText("0/120字");
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        cb_control_identity_validity_time.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked) {
                    tv_control_identity_validity.setText("");
                }
            }
        });
    }

    @OnClick({R.id.leftButton, R.id.rl_select_occupation, R.id.tv_certificates_validity,
            R.id.tv_register_step_2_identity_statement, R.id.iv_register_step_2_identity_statement,
            R.id.rl_tv_tax_live_address_country_layout, R.id.rl_tax_birthplace_address_country,
            R.id.rl_tax_live_address_province_layout, R.id.rl_tax_live_address_city_layout, R.id.rl_tips_flag,
            R.id.rl_tax_birthplace_address_province_layout, R.id.rl_tax_birthplace_address_city_layout,
            R.id.iv_control_identityType, R.id.tv_control_identityType, R.id.tv_control_identity_validity,
            R.id.tv_beneficial_identityType, R.id.iv_beneficial_identityType, R.id.tv_beneficial_identity_validity,

    })
    public void onClick(View view) {
        if (!isFastDoubleClick()) {
            collapseSoftInputMethod(view.getWindowToken());
            switch (view.getId()) {
                case R.id.leftButton:
                    finish();
                    break;
                case R.id.rl_tips_flag:
                    TipPopwindowHelper popwindowHelper = TipPopwindowHelper.getInstance(this);
                    popwindowHelper.initPopwindow();
                    if ("OF".equals(identStatement)) { //仅非居民(OF) 3：即使中国税收居民又是他国税收居民(NF), 仅中国ON
                        popwindowHelper.setTextContent(getString(R.string.tips_no_tax_man));
                    } else if ("ON".equals(identStatement)) {
                        popwindowHelper.setTextContent(getString(R.string.tips_tax_man));
                    }
                    popwindowHelper.showPopLocation(tv_tips_flag);

                    break;

                case R.id.rl_select_occupation: //选择职业
                    currentType = 2;
                    currentPosition = 0;
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getProfession(true);
                    }
                    break;
                case R.id.tv_certificates_validity://选择证件有效期
                    if ("0".equals(mentorApplication.accountLoginBean.getData().getIdentityType())) {
                        showDialogType = 2;
                        showConfirmAlert(this, "温馨提示", "修改证件有效期需重新扫描并上传身份证，请确认是否继续", "放弃", "继续");
                    } else {
                        datePickerType = 100;
                        selectCertificatesValidity();
                    }
                    break;

                case R.id.iv_control_identityType: //账户他人控制点击身份证
                case R.id.tv_control_identityType: //账户他人控制点击身份证
                    currentType = 15;
                    currentPosition = 0;
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getIndentityType(true);
                    }
                    break;
                case R.id.tv_control_identity_validity: //账户他人证件有效期
                    datePickerType = 101;
                    selectCertificatesValidity();
                    break;
                case R.id.tv_beneficial_identityType: //受益人点击身份证
                case R.id.iv_beneficial_identityType: //受益人点击身份证
                    currentType = 16;
                    currentPosition = 0;
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getIndentityType(true);
                    }
                    break;
                case R.id.tv_beneficial_identity_validity: //受益人证件有效期
                    datePickerType = 102;
                    selectCertificatesValidity();
                    break;

                case R.id.tv_register_step_2_identity_statement: //点击居民身份声明
                case R.id.iv_register_step_2_identity_statement://居民身份声明
                    currentType = 5;

                    identity_statementPopShow = true;
                    currentPosition = 0;

                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getTaxType(false);
                    }
                    break;
                case R.id.rl_tv_tax_live_address_country_layout://现居地国别
                    currentType = 6;
                    currentPosition = 0;
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getCountry(true);
                    }
                    break;
                case R.id.rl_tax_birthplace_address_country://出生地国别
                    currentType = 7;
                    currentPosition = 0;
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getCountry(true);
                    }
                    break;
                case R.id.rl_tax_live_address_province_layout://现居地 省
                    if (TextUtils.isEmpty(liveAddressCountryId)) {
                        showToast("请先选择国别");
                        return;
                    }
                    if (!ParamUtil.isSelectTaxCountry(liveAddressCountryId)) {
                        return;
                    }
                    currentType = 11;
                    currentPosition = 0;
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getTaxProvince(true);
                    }
                    break;
                case R.id.rl_tax_live_address_city_layout: //现居地 市
                    if (TextUtils.isEmpty(liveAddressProvinceCode)) {
                        showToast("请先选择您现居地所在的省");
                        return;
                    }
                    currentType = 12;
                    currentPosition = 0;
                    taxCityList.clear();
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getTaxCity(0, liveAddressProvinceCode, true);
                    }
                    break;
                case R.id.rl_tax_birthplace_address_province_layout: //出生地省
                    if (TextUtils.isEmpty(birthAddressCountryId)) {
                        showToast("请先选择国别");
                        return;
                    }

                    if (!ParamUtil.isSelectTaxCountry(birthAddressCountryId)) {
                        return;
                    }
                    currentType = 13;
                    currentPosition = 0;
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getTaxProvince(true);
                    }
                    break;
                case R.id.rl_tax_birthplace_address_city_layout: //出生地市
                    if (TextUtils.isEmpty(birthAddressProvinceCode)) {
                        showToast("请先选择您出生地所在的省");
                        return;
                    }
                    currentType = 14;
                    currentPosition = 0;
                    taxCityList.clear();
                    initPopList();
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getTaxCity(0, birthAddressProvinceCode, true);
                    }
                    break;

            }
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (datePickerView != null && datePickerView.isShowing()) {
                datePickerView.dismiss();
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }


    /**
     * 查询职业数据
     *
     * @param isShowPop
     */
    private void getProfession(final boolean isShowPop) {
        OkGo.<String>post(HostConstant.QUERY_PROFESSION)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, null))
                .execute(new com.lzy.okgo.callback.StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        UpdateProfession(response.body(), isShowPop);
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    private void UpdateProfession(String json, boolean isShowPop) {
        professionList.clear();
        list.clear();

        QueryProfessionBean bean;
        try {
            bean = new Gson().fromJson(json, QueryProfessionBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        professionList.addAll(bean.getData());
        initPopList();
        setProfession();
        if (isShowPop) {
            showPicker();
        }
    }

    private void initPopList() {
        list.clear();

        switch (currentType) {
            case 2:
                for (QueryProfessionBean.DataBean dataBean : professionList) {
                    list.add(dataBean.getProfessionName());
                }
                break;
            case 3:
            case 11:
            case 13:
                for (QueryTaxProvinceCityBean.DataBean dataBean : taxProvinceList) {
                    list.add(dataBean.getRegionNameCn());
                }
                break;
            case 4:
            case 12:
            case 14:
                for (QueryTaxProvinceCityBean.DataBean dataBean : taxCityList) {
                    list.add(dataBean.getRegionNameCn());
                }
                break;
            case 5:
                for (QueryCountryBean.DataBean dataBean : taxTypeList) {
                    list.add(dataBean.getItemName());
                }
                break;
            case 6:
            case 7:
            case 100:
            case 101:
            case 102:
            case 103:
            case 104:
            case 105:
            case 106:
            case 107:
            case 108:
            case 109:
                for (QueryCountryBean.DataBean dataBean : countryList) {
                    list.add(dataBean.getItemName());
                }
                break;
            case 15:
            case 16:
                for (QueryCertificateTypeBean.DataBean dataBean : identityTypeList) {
                    list.add(dataBean.getTypeName());
                }
                break;
            default:
                break;
        }

    }

    private void showPicker() {
        nomarlPickerPopupWindow = new NomarlPickerPopupWindow(mActivity, itemsOnClick, list);
        nomarlPickerPopupWindow.showAtLocation(activity_user_info_edit_root,
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

        switch (currentType) {
            case 2:
                nomarlPickerPopupWindow.setTitle_str("请选择您的职业");
                break;
            case 3:
                nomarlPickerPopupWindow.setTitle_str("请选择您所在的省");
                break;
            case 4:
                nomarlPickerPopupWindow.setTitle_str("请选择您所在的市");
                break;
            case 5:
                nomarlPickerPopupWindow.setTitle_str("请选择居民身份类型");
                break;
            case 6:
            case 7:
            case 100:
            case 101:
            case 102:
            case 103:
            case 104:
            case 105:
            case 106:
            case 107:
            case 108:
            case 109:
                nomarlPickerPopupWindow.setTitle_str("请选择国别或地区");
                break;
            case 15:
                nomarlPickerPopupWindow.setTitle_str("请选择他人控制身份证");
                break;
            case 16:
                nomarlPickerPopupWindow.setTitle_str("请选择受益人身份证");
                break;
            default:
                break;
        }

        nomarlPickerPopupWindow.setOnPickerChangeListener(
                new NomarlPickerPopupWindow.OnPickerChangeListener() {
                    @Override
                    public void onPickerChange(int position) {
                        currentPosition = position;
                    }
                });

    }

    //为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nomarlPickerPopupWindow.dismiss();
            switch (v.getId()) {
                case R.id.btn_cancel:
                    if (nomarlPickerPopupWindow != null) {
                        nomarlPickerPopupWindow.dismiss();
                    }
                    break;
                case R.id.btn_sure:
                    if (nomarlPickerPopupWindow != null) {
                        selectPosition = currentPosition;
                        nomarlPickerPopupWindow.dismiss();

                        switch (currentType) {
                            case 2:
                                tv_occupation_name.setText(list.get(selectPosition));
                                profession = professionList.get(selectPosition).getProfessionCode();
                                break;
                            case 3:
                                break;
                            case 4:
                                break;
                            case 5:
                                String oldStatement = tv_register_step_2_identity_statement.getText().toString();
                                tv_register_step_2_identity_statement.setText(list.get(selectPosition));
                                identStatement = taxTypeList.get(selectPosition).getItemValue();
                                //为了解决网上交易开户未选中声明第一条其他纳税人不展示的问题
                                if (oldStatement.equals(getString(R.string.string_tax_identity_statement))) {
                                    taxLayoutShow(identStatement, true);
                                    return;
                                }
                                //为了解决重复选择仅中国税收居民第一条其他纳税人不展示的问题
                                if (!oldStatement.equals(list.get(selectPosition))) {
                                    taxLayoutShow(identStatement, false);
                                }
                                break;
                            case 6:
                                tv_tax_live_address_country.setText(list.get(selectPosition));
                                if (liveAddressCountryId != countryList.get(selectPosition).getItemValue()) {
                                    tv_tax_live_address_province.setText("");
                                    tv_tax_live_address_city.setText("");
                                    liveAddressProvinceCode = "";
                                    liveAddressCityCode = "";
                                }

                                liveAddressCountryId = countryList.get(selectPosition).getItemValue();
                                if (ParamUtil.isSelectTaxCountry(liveAddressCountryId)) {
                                    hwet_tax_live_address_province.setVisibility(View.GONE);
                                    tv_tax_live_address_province.setVisibility(View.VISIBLE);
                                    iv_tax_live_address_province.setVisibility(View.VISIBLE);

                                    hwet_tax_live_address_city.setVisibility(View.GONE);
                                    tv_tax_live_address_city.setVisibility(View.VISIBLE);
                                    iv_tax_live_address_city.setVisibility(View.VISIBLE);

                                    ll_live_chinese_address_container.setVisibility(View.VISIBLE);
                                    ll_live_nochinese_address_container.setVisibility(View.GONE);
                                } else {
                                    hwet_tax_live_address_province.setVisibility(View.VISIBLE);
                                    tv_tax_live_address_province.setVisibility(View.INVISIBLE);
                                    iv_tax_live_address_province.setVisibility(View.INVISIBLE);

                                    hwet_tax_live_address_city.setVisibility(View.VISIBLE);
                                    tv_tax_live_address_city.setVisibility(View.INVISIBLE);
                                    iv_tax_live_address_city.setVisibility(View.INVISIBLE);

                                    ll_live_nochinese_address_container.setVisibility(View.VISIBLE);
                                    ll_live_chinese_address_container.setVisibility(View.GONE);
                                }
                                break;
                            case 7:
                                tv_tax_birthplace_address_country.setText(list.get(selectPosition));
                                if (birthAddressCountryId != countryList.get(selectPosition).getItemValue()) {
                                    tv_tax_birthplace_address_province.setText("");
                                    tv_tax_birthplace_address_city.setText("");
                                    birthAddressProvinceCode = "";
                                    birthAddressCityCode = "";
                                }
                                birthAddressCountryId = countryList.get(selectPosition).getItemValue();
                                if (ParamUtil.isSelectTaxCountry(birthAddressCountryId)) { //是中国则省市可选,否则需要输入
                                    hwet_tax_birthplace_address_province.setVisibility(View.GONE);
                                    tv_tax_birthplace_address_province.setVisibility(View.VISIBLE);
                                    iv_tax_birthplace_address_province.setVisibility(View.VISIBLE);

                                    hwet_tax_birthplace_address_city.setVisibility(View.GONE);
                                    tv_tax_birthplace_address_city.setVisibility(View.VISIBLE);
                                    iv_tax_birthplace_address_city.setVisibility(View.VISIBLE);
                                } else {
                                    hwet_tax_birthplace_address_province.setVisibility(View.VISIBLE);
                                    tv_tax_birthplace_address_province.setVisibility(View.GONE);
                                    iv_tax_birthplace_address_province.setVisibility(View.GONE);

                                    hwet_tax_birthplace_address_city.setVisibility(View.VISIBLE);
                                    tv_tax_birthplace_address_city.setVisibility(View.GONE);
                                    iv_tax_birthplace_address_city.setVisibility(View.GONE);
                                }
                                break;
                            case 11:
                                tv_tax_live_address_province.setText(list.get(selectPosition));
                                if (liveAddressProvinceCode != getSelectProvinceCode(liveAddressCountryId, selectPosition)) {
                                    tv_tax_live_address_city.setText("");
                                    liveAddressCityCode = "";
                                }
                                liveAddressProvinceCode = getSelectProvinceCode(liveAddressCountryId, selectPosition);
                                break;
                            case 12:
                                tv_tax_live_address_city.setText(list.get(selectPosition));
                                liveAddressCityCode = taxCityList.get(selectPosition).getRegionCode();
                                break;
                            case 13:
                                tv_tax_birthplace_address_province.setText(list.get(selectPosition));
                                if (birthAddressProvinceCode != getSelectProvinceCode(birthAddressCountryId, selectPosition)) {
                                    tv_tax_birthplace_address_city.setText("");
                                    birthAddressCityCode = "";
                                }
                                birthAddressProvinceCode = getSelectProvinceCode(birthAddressCountryId, selectPosition);
                                break;
                            case 14:
                                tv_tax_birthplace_address_city.setText(list.get(selectPosition));
                                birthAddressCityCode = taxCityList.get(selectPosition).getRegionCode();
                                break;
                            case 15:
                                tv_control_identityType.setText(list.get(selectPosition));
                                controllerCertType = identityTypeList.get(selectPosition).getTypeValue();
                                break;
                            case 16:
                                tv_beneficial_identityType.setText(list.get(selectPosition));
                                beneficiaryCertType = identityTypeList.get(selectPosition).getTypeValue();
                                break;
                            //以下为其他纳税人选择的识别国
                            case 100:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(0).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(0).setTaxPayerCountryId(countryList.get(selectPosition).getItemValue());
                                break;
                            case 101:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(1).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(1).setTaxPayerCountryId(countryList.get(selectPosition).getItemValue());
                                break;
                            case 102:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(2).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(2).setTaxPayerCountryId(countryList.get(selectPosition).getItemValue());
                                break;
                            case 103:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(3).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(3).setTaxPayerCountryId(countryList.get(selectPosition)
                                        .getItemValue());
                                break;
                            case 104:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(4).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(4).setTaxPayerCountryId(countryList.get(selectPosition)
                                        .getItemValue());
                                break;
                            case 105:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(5).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(5).setTaxPayerCountryId(countryList.get(selectPosition)
                                        .getItemValue());
                                break;
                            case 106:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(6).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(6).setTaxPayerCountryId(countryList.get(selectPosition)
                                        .getItemValue());
                                break;
                            case 107:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(7).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(7).setTaxPayerCountryId(countryList.get(selectPosition)
                                        .getItemValue());
                                break;
                            case 108:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(8).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(8).setTaxPayerCountryId(countryList.get(selectPosition)
                                        .getItemValue());
                                break;
                            case 109:
                                tv_tax_ident_num_country.setText(list.get(selectPosition));
                                taxPayersTotal.get(9).setTaxPayerCountry(list.get(selectPosition));
                                taxPayersTotal.get(9).setTaxPayerCountryId(countryList.get(selectPosition)
                                        .getItemValue());
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    };

    /**
     * 选择证件有效期
     */
    private void selectCertificatesValidity() {
        //时间选择器
        datePickerView = new DatePickerView(mActivity, MentorConst.DateType.YEAR_MONTH_DAY);

        //控制时间范围
        Date date = new Date();//取时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(calendar.DATE, 1);//1往后一天，-1提前一天
//                Calendar calendar = Calendar.getInstance();
        //要在setTime 之前才有效果哦
        //System.out.println(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + (calendar.get(Calendar.DAY_OF_MONTH)));
        datePickerView.setCurrentTime(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.DAY_OF_MONTH));
        datePickerView.setRange(calendar.get(Calendar.YEAR), 2118);
        datePickerView.setTime(new Date());
        datePickerView.setCyclic(false);
        datePickerView.setCancelable(true);
        //时间选择后回调
        datePickerView.setOnTimeSelectListener(mDatePickerSelectLinstener);
        datePickerView.show();
    }

    /**
     * 初始化用户数据
     *
     * @param bean
     */
    private void initUserInfo(QueryUserInfoBean bean) {

        QueryUserInfoBean.DataBean data = bean.getData();
        if (data == null) {
            return;
        }
        tv_user_name.setText(data.getRealName());
        if ("1".equals(data.getCertificateValidEver())) {//长期有效
            cbox_certificates_validity.setChecked(true);
            tv_certificates_validity.setText("");
        } else {
            cbox_certificates_validity.setChecked(false);
            tv_certificates_validity.setText(data.getCertificateValidTerm());
        }
        et_email.setText(data.getEmail());//et_email
        if (!StringUtils.isNullOrEmpty(data.getProfession())) {//职业名称
            profession = data.getProfession();
            setProfession();
        }
        //3.0.7新增职务
        et_user_info_duty.setText(data.getOccupation());
        et_address.setText(data.getContactAddress());//地址
        et_zip_code.setText(data.getPostCode());//邮编

        //3.0.7新增 账户是否是他人控制
        if ("1".equals(data.getIsExistActualControl())) { //账户是否是他人控制
            sbtn_is_others_control.setChecked(true);
            et_others_control_name.setText(data.getControllerName());
            et_control_identity.setText(data.getControllerCertNo());
            controllerCertType = data.getControllerCertType();
            tv_control_identityType.setText(choiceIdentityName(data.getControllerCertType()));
            if ("1".equals(data.getControllerCertValidEver())) { //身份证长期有效
                cb_control_identity_validity_time.setChecked(true);
                tv_control_identity_validity.setText("长期有效");
            } else {
                cb_control_identity_validity_time.setChecked(false);
                tv_control_identity_validity.setText(data.getControllerCertValidTerm());
            }
            String controllerInstruction = data.getControllerInstruction();
            if (!TextUtils.isEmpty(controllerInstruction)) {
                et_control_cause.setText(controllerInstruction);
                tv_control_length.setText(controllerInstruction.length() + "/120字");
            }

        } else {
            sbtn_is_others_control.setChecked(false);
        }
        //3.0.7新增 实际受益人是否是本人
        if ("1".equals(data.getActualBeneficiaryRelation())) {
            sbtn_is_beneficial_owner.setChecked(false);
            et_beneficial_owner_name.setText(data.getBeneficiaryName());
            et_beneficial_owner_identity.setText(data.getBeneficiaryCertNo());
            beneficiaryCertType = data.getBeneficiaryCertType();
            tv_beneficial_identityType.setText(choiceIdentityName(data.getBeneficiaryCertType()));
            et_beneficial_owner_cause.setText(data.getBeneficiaryInstruction());
            if ("1".equals(data.getBeneficiaryCertValidEver())) { //身份证长期有效
                cb_beneficial_identity_validity_time.setChecked(true);
                tv_beneficial_identity_validity.setText("长期有效");
            } else {
                cb_beneficial_identity_validity_time.setChecked(false);
                tv_beneficial_identity_validity.setText(data.getBeneficiaryCertValidTerm());
            }
        } else {
            sbtn_is_beneficial_owner.setChecked(true);
        }
        //3.07新增 不良记录
        if ("1".equals(data.getHasBadCreditRecords())) {
            sbtn_is_bad_record.setChecked(true);
            String badCreditRecords = data.getBadCreditRecords();
            if (!TextUtils.isEmpty(badCreditRecords)) {
                et_bad_record.setText(badCreditRecords);
                tv_bad_record_length.setText(badCreditRecords.length() + "/120字");
            }
        } else {
            sbtn_is_bad_record.setChecked(false);
        }

        userBeanTax = bean;
        bindTaxData(bean);
    }

    /**
     * 通过证件类型筛选证件名称
     *
     * @param identityType
     * @return
     */
    String identityName = "";

    private String choiceIdentityName(String identityType) {

        if (identityTypeList != null && identityTypeList.size() > 0) {
            if (!StringUtils.isNullOrEmpty(identityType)) {
                for (QueryCertificateTypeBean.DataBean dataBean : identityTypeList) {
                    if (identityType.equals(dataBean.getTypeValue())) {
                        identityName = dataBean.getTypeName();
                    }
                }
            }
        }
        return identityName;
    }

    private void updateUserInfo(String json) {
        BaseBean bean;
        try {
            bean = new Gson().fromJson(json, BaseBean.class);
        } catch (Exception e) {
            Logger.e(TAG, "Gson解析数据时发生异常");
            showConfirmAlert(this, "提示", "数据解析错误");
            e.printStackTrace();
            return;
        }

        if (!CommonUtil.checkState(this, bean, json)) {
            return;
        }

        if ("0000".equals(bean.getRespCode())) {
            PreferencesUtils.putString(this, this.mentorApplication.getAccountLoginBean().getData().getIdentityNo() +
                    "isMoneyValidate", "true" + ":" + "反洗钱全");
            ToastUtils.showShort("修改成功");
        }
        mentorApplication.accountLoginBean.getData().setCertificateValidEver(paramsModifyUserInfo.get("certificateValidEver"));

        if ("1".equals(mentorApplication.accountLoginBean.getData().getCertificateValidEver())) {//长期有效
            mentorApplication.accountLoginBean.getData().setCertificateValidTerm("");
        } else {
            mentorApplication.accountLoginBean.getData().setCertificateValidTerm("" + paramsModifyUserInfo.get("certificateValidTerm"));
        }
        mentorApplication.accountLoginBean.getData().setPostCode(paramsModifyUserInfo.get("postCode"));//邮编
        mentorApplication.accountLoginBean.getData().setEmail(paramsModifyUserInfo.get("email"));//setEmail
        mentorApplication.accountLoginBean.getData().setProfession(paramsModifyUserInfo.get("professionCode"));//职业
        mentorApplication.accountLoginBean.getData().setContactAddress(paramsModifyUserInfo.get("contactAddress"));//地址
        setResult(RESULT_OK);
        finish();
    }

    /**
     * 设置用户已保存的职业
     */
    private void setProfession() {
        if (!StringUtils.isNullOrEmpty(profession)) {//职业名称
            if (professionList.size() != 0) {
                for (QueryProfessionBean.DataBean beanProfession : professionList) {
                    if (profession.equals(beanProfession.getProfessionCode())) {
                        tv_occupation_name.setText(beanProfession.getProfessionName());//职业名称
                        break;
                    }
                }
            }
        }
    }


    ///////////////////////////个人涉税逻辑
    QueryUserInfoBean userBeanTax;
    private List<QueryCountryBean.DataBean> countryList = new ArrayList<>();
    private List<QueryCountryBean.DataBean> taxTypeList = new ArrayList<>();

    //默认是
    private String identStatementOnlyChina = "ON";
    /**
     * 居民身份申明
     */
    private String identStatement = "";//居民身份申明
    private String liveAddressCountryId;//现居地国别
    private String liveAddressProvinceCode = "";//现居地 - 省
    private String liveAddressCityCode = "";//现居地 - 市
    private String birthAddressCountryId;//出生地国别
    private String birthAddressProvinceCode = "";//出生地 - 省
    private String birthAddressCityCode = "";//出生地 - 市
    private boolean identity_statementPopShow = false;//居民身份申明 选择框是否弹出
    private boolean isBindIdentityType = false;
    private boolean isBindLiveCountryType = false;//是否已经绑定上出生地国家名称  主要是防止在绑定用户信息是 国家接口还没有返回数据
    private boolean isBindBirthCountryType = false;//是否已经绑定上居住地国家名称  主要是防止在绑定用户信息是 国家接口还没有返回数据
    private boolean isBindLiveProvince = false;
    private boolean isBindBirthProvince = false;

    private void bindTaxData(QueryUserInfoBean bean) {
        identStatement = bean.getData().getTaxType();
        taxLayoutShow(identStatement, true);
        queryTaxTypeName();
        if ("8".equals(bean.getData().getIdentityType()) || "9".equals(bean.getData().getIdentityType())
                || "2".equals(bean.getData().getIdentityType()) || identStatementOnlyChina.equals(identStatement)
                || "NO".equals(identStatement)) {
            return;
        }

        QueryUserInfoBean.DataBean userInfoBean = bean.getData();

        //税收居民信息
        et_tax_name.setText(userInfoBean.getNameEn());//名（英文）
        et_tax_surname.setText(userInfoBean.getSurnameEn());//姓（英文

        //现居住地详细地址
        liveAddressCountryId = userInfoBean.getDomicileCountryCn();//居住地-国家
        String liveCountryName = getCountryName(liveAddressCountryId);
        if (!StringUtils.isNullOrEmpty(liveCountryName)) {
            isBindLiveCountryType = true;
            tv_tax_live_address_country.setText(liveCountryName);
        }
        if (ParamUtil.isSelectTaxCountry(liveAddressCountryId)) {
            hwet_tax_live_address_province.setVisibility(View.GONE);
            tv_tax_live_address_province.setVisibility(View.VISIBLE);
            iv_tax_live_address_province.setVisibility(View.VISIBLE);
            hwet_tax_live_address_city.setVisibility(View.GONE);
            tv_tax_live_address_city.setVisibility(View.VISIBLE);
            iv_tax_live_address_city.setVisibility(View.VISIBLE);
            ll_live_chinese_address_container.setVisibility(View.VISIBLE);
            ll_live_nochinese_address_container.setVisibility(View.GONE);
            liveAddressProvinceCode = userInfoBean.getDomicileProvinceCn();//居住地-省份
            liveAddressCityCode = userInfoBean.getDomicileCityCn();//居住地-城市
            String liveProvinceName = getProvinceName(liveAddressProvinceCode);
            if (!StringUtils.isNullOrEmpty(liveProvinceName)) {
                isBindLiveProvince = true;
                tv_tax_live_address_province.setText(liveProvinceName);
            }
            getTaxCity(3, liveAddressProvinceCode, false);
            et_tax_live_chinese_address.setText(userInfoBean.getDomicileLocationCn());//居住地-地址-中文
            et_tax_live_pinyin_address.setText(userInfoBean.getDomicileLocationEn());//居住地-地址-拼音
        } else {
            hwet_tax_live_address_province.setVisibility(View.VISIBLE);
            tv_tax_live_address_province.setVisibility(View.GONE);
            iv_tax_live_address_province.setVisibility(View.GONE);
            hwet_tax_live_address_city.setVisibility(View.VISIBLE);
            tv_tax_live_address_city.setVisibility(View.GONE);
            iv_tax_live_address_city.setVisibility(View.GONE);
            ll_live_nochinese_address_container.setVisibility(View.VISIBLE);
            ll_live_chinese_address_container.setVisibility(View.GONE);
            hwet_tax_live_address_province.setText(userInfoBean.getDomicileProvinceCn());//居住地-省份
            hwet_tax_live_address_city.setText(userInfoBean.getDomicileCityCn());//居住地-城市
            et_tax_live_english_address.setText(userInfoBean.getDomicileLocationEn());//居住地-地址- 英文
        }
        //出生地详细地址
        birthAddressCountryId = userInfoBean.getBirthplaceCountryCn();//出生地-国家
        String birthCountryName = getCountryName(birthAddressCountryId);
        if (!StringUtils.isNullOrEmpty(birthCountryName)) {
            isBindBirthCountryType = true;
            tv_tax_birthplace_address_country.setText(birthCountryName);
        }
        if (ParamUtil.isSelectTaxCountry(birthAddressCountryId)) {
            hwet_tax_birthplace_address_province.setVisibility(View.GONE);
            tv_tax_birthplace_address_province.setVisibility(View.VISIBLE);
            iv_tax_birthplace_address_province.setVisibility(View.VISIBLE);
            hwet_tax_birthplace_address_city.setVisibility(View.GONE);
            tv_tax_birthplace_address_city.setVisibility(View.VISIBLE);
            iv_tax_birthplace_address_city.setVisibility(View.VISIBLE);
            birthAddressProvinceCode = userInfoBean.getBirthplaceProvinceCn();//出生地-省份-中文
            birthAddressCityCode = userInfoBean.getBirthplaceCityCn();//出生地-城市-中文

            String birthProvinceName = getProvinceName(birthAddressProvinceCode);
            if (!StringUtils.isNullOrEmpty(birthProvinceName)) {
                isBindBirthProvince = true;
                tv_tax_birthplace_address_province.setText(birthProvinceName);
            }
            getTaxCity(4, birthAddressProvinceCode, false);
        } else {
            hwet_tax_birthplace_address_province.setVisibility(View.VISIBLE);
            tv_tax_birthplace_address_province.setVisibility(View.GONE);
            iv_tax_birthplace_address_province.setVisibility(View.GONE);
            hwet_tax_birthplace_address_city.setVisibility(View.VISIBLE);
            tv_tax_birthplace_address_city.setVisibility(View.GONE);
            iv_tax_birthplace_address_city.setVisibility(View.GONE);
            hwet_tax_birthplace_address_province.setText(userInfoBean.getBirthplaceProvinceCn());//出生地-省份
            hwet_tax_birthplace_address_city.setText(userInfoBean.getBirthplaceCityCn());//出生地-城市
        }
        //  其他纳税人
        List<TaxTaxpayernoInfoRequestsBean> taxTaxpayernoInfoRequests = userInfoBean.getTaxTaxpayernoInfoRequests();
        if (taxTaxpayernoInfoRequests == null || taxTaxpayernoInfoRequests.size() <= 0) {
            if ("OF".equals(identStatement) || "NF".equals(identStatement)) { //为了兼容存量用户没有其他纳税人,默认展示一条
                taxPayerAdapter.addData(0);
                taxPayersTotal.clear();
                taxPayersTotal.addAll(taxPayersContainer);
            }
            return;
        }
        ParamUtil.setCountryList(countryList);
        taxPayersTotal = ParamUtil.formatTaxPayerInfos(taxTaxpayernoInfoRequests);
        taxPayersContainer.addAll(taxPayersTotal);
        if (taxPayerAdapter != null) {
            taxPayerAdapter.notifyDataSetChanged();
        }
    }

    private void queryTaxTypeName() {
        if (taxTypeList != null && taxTypeList.size() > 0) {
            for (QueryCountryBean.DataBean data : taxTypeList) {
                if (data.getItemValue().equals(identStatement)) {
                    isBindIdentityType = true;
                    tv_register_step_2_identity_statement.setText(data.getItemName());
                }
            }
        }
    }

    /**
     * 根据国家id查询国家名称
     *
     * @param code
     * @return
     */
    private String getCountryName(String code) {
        for (QueryCountryBean.DataBean countryBean : countryList) {
            if (countryBean.getItemValue().equals(code)) {
                return countryBean.getItemName();
            }
        }
        return null;
    }

    /**
     * 根据省编码查询对应的省名称
     *
     * @param code
     * @return
     */
    private String getProvinceName(String code) {
        for (QueryTaxProvinceCityBean.DataBean provinceBean : taxProvinceList) {
            if (provinceBean.getRegionCode().equals(code)) {
                return provinceBean.getRegionNameCn();
            }
        }
        return null;
    }

    /**
     * 根据选择的 居民身份 进行判断初始化那些 有关涉税的布局模块
     *
     * @param identStatement 1：仅中国税收居民(ON) 2：仅非居民(OF) 3：即使中国税收居民又是他国税收居民(NF)
     *                       N0是无需申明,app现在没有这个选项
     * @param isFirstShow
     */
    private void taxLayoutShow(String identStatement, boolean isFirstShow) {
        ll_tax_user_info_layout.setVisibility(View.GONE);//个人信息
        ll_tax_live_address_layout.setVisibility(View.GONE);//现居住详细地址
        ll_tax_birthplace_address_layout.setVisibility(View.GONE);//出生地
        tv_other_taxpayer.setVisibility(View.GONE);//添加其他纳税人
        rl_tips_flag.setVisibility(View.GONE);
        if (!StringUtils.isNullOrEmpty(identStatement)) {
            //为了解决第一次进入页面仅中国税收居民第一条数据不展示问题
            if (isFirstShow) {
                if (identStatementOnlyChina.equals(identStatement) || "NO".equals(identStatement)) {
                    taxPayerAdapter.addData(0);
                }
            }
            if (identStatementOnlyChina.equals(identStatement) || "NO".equals(identStatement)) {
                tv_other_taxpayer.setVisibility(View.GONE);//添加其他纳税人
                if (identStatementOnlyChina.equals(identStatement)) {
                    rl_tips_flag.setVisibility(View.VISIBLE);
                } else {
                    rl_tips_flag.setVisibility(View.GONE);
                }
                taxPayersTotal.clear();
                taxPayersTotal.addAll(taxPayersContainer);
                clearRecyclerView();
            } else {
                //3.0.8新增
                if ("OF".equals(identStatement)) {
                    rl_tips_flag.setVisibility(View.VISIBLE);
                }
                ll_tax_user_info_layout.setVisibility(View.VISIBLE);//个人信息
                ll_tax_live_address_layout.setVisibility(View.VISIBLE);//现居住地址
                ll_tax_birthplace_address_layout.setVisibility(View.VISIBLE);//出生地
                tv_other_taxpayer.setVisibility(View.VISIBLE);//添加其他纳税人
                taxPayersContainer.clear();
                taxPayersContainer.addAll(taxPayersTotal);
            }
        } else {
            taxPayerAdapter.addData(0);
            taxPayersTotal.clear();
            taxPayersTotal.addAll(taxPayersContainer);
            clearRecyclerView();
        }
    }

    /**
     * 对个人涉税相关信息进行检查  填写是否合理
     *
     * @return
     */
    private boolean paramsCheckTax() {
        if (userBeanTax == null || userBeanTax.getData() == null
                || "8".equals(userBeanTax.getData().getIdentityType())
                || "9".equals(userBeanTax.getData().getIdentityType())
                || "2".equals(userBeanTax.getData().getIdentityType())) {
            return true;
        }
        if (checkParam(identStatement, "请选择居民身份")) {
            return false;
        }
        //网上交易开户无需声明为NO校验
        if ("NO".equals(identStatement)) {
            showConfirmAlert(mActivity, "提示", "请选择居民身份");
            return false;
        }
        if (identStatementOnlyChina.equals(identStatement)) {
            if (!cb_ident_shengming_info.isChecked()) {
                showConfirmAlert(mActivity, "提示", "请勾选声明确认");
                return false;
            }
            return true;
        }
        if (checkParam(et_tax_surname.getText().toString(), "请输入姓")) {
            et_tax_surname.setIsSelected(true);
            return false;
        }
        if (checkParamLength(et_tax_surname.getText().toString().length(), 60, "姓最大长度为60")) {
            et_tax_surname.setIsSelected(true);
            return false;
        }
        if (checkParam(et_tax_name.getText().toString(), "请输入名")) {
            et_tax_name.setIsSelected(true);
            return false;
        }
        if (checkParamLength(et_tax_name.getText().toString().length(), 60, "名最大长度为60")) {
            et_tax_name.setIsSelected(true);
            return false;
        }

        if (checkParam(liveAddressCountryId, "请选择现居地国别")) {
            return false;
        }
        if (ParamUtil.isSelectTaxCountry(liveAddressCountryId)) {
            if (checkParam(liveAddressProvinceCode, "请选择现居地省")) {
                return false;
            }
            if (checkParam(liveAddressCityCode, "请选择现居地市")) {
                return false;
            }
            if (checkParam(et_tax_live_chinese_address.getText().toString(), "请输入现居地中文地址")) {
                et_tax_live_chinese_address.setIsSelected(true);
                return false;
            }

            if (checkParamLength(et_tax_live_chinese_address.getText().toString().length(), 60, "现居地中文地址最大长度为60")) {
                et_tax_live_chinese_address.setIsSelected(true);
                return false;
            }

            if (checkParam(et_tax_live_pinyin_address.getText().toString(), "请输入现居地拼音地址")) {
                et_tax_live_chinese_address.setIsSelected(true);
                return false;
            }
            if (checkParamLength(et_tax_live_pinyin_address.getText().toString().length(), 60, "现居地市拼音地址最大长度为60")) {
                et_tax_live_chinese_address.setIsSelected(true);
                return false;
            }
        } else {
            if (checkParam(et_tax_live_english_address.getText().toString(), "请输入现居地英文地址")) {
                et_tax_live_english_address.setIsSelected(true);
                return false;
            }

            if (checkParamLength(et_tax_live_english_address.getText().toString().length(), 60, "现居地市英文地址最大长度为60")) {
                et_tax_live_english_address.setIsSelected(true);
                return false;
            }
        }


        if (checkParam(birthAddressCountryId, "请选择出生地国别")) {
            return false;
        }

        if (ParamUtil.isSelectTaxCountry(birthAddressCountryId)) {
            if (checkParam(birthAddressProvinceCode, "请选择出生地省")) {
                return false;
            }
            if (checkParam(birthAddressCityCode, "请选择出生地市")) {
                return false;
            }
        } else {
            if (checkParam(hwet_tax_birthplace_address_province.getText().toString(), "请输入出生地省")) {
                hwet_tax_birthplace_address_province.setIsSelected(true);
                return false;
            }

            if (checkParam(hwet_tax_birthplace_address_city.getText().toString(), "请输入出生地省")) {
                hwet_tax_birthplace_address_city.setIsSelected(true);
                return false;
            }
        }
        // 校验是否取得纳税人识别号
        if (!ParamUtil.checkedTaxPayersParam(taxPayersTotal)) {
            showConfirmAlert(this, "请补全其他纳税人信息");
            return false;
        }

        if (!cb_ident_shengming_info.isChecked()) {
            showConfirmAlert(mActivity, "提示", "请勾选声明确认");
            return false;
        }
        return true;
    }

    /**
     * 获取证件类型
     *
     * @param isShowPop
     */
    private void getIndentityType(final boolean isShowPop) {
        Map<String, String> params = new HashMap<>();
        params.put("type", "1");
        OkGo.<String>post(HostConstant.QUERY_CERTIFICATE_TYPE)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, params))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        UpdateIdType(response.body(), isShowPop);
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    private void UpdateIdType(String json, boolean isShowPop) {
        identityTypeList.clear();

        QueryCertificateTypeBean bean;
        try {
            bean = new Gson().fromJson(json, QueryCertificateTypeBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        identityTypeList.addAll(bean.getData());
        initPopList();

        if (isFirstComing) {
            isFirstComing = false;
            selectPosition = 0;
            tv_control_identityType.setText(identityTypeList.get(selectPosition).getTypeName().length() > 4 ?
                    identityTypeList.get(selectPosition).getTypeName().substring(0, 4) :
                    identityTypeList.get(selectPosition).getTypeName());
        }
        if (isShowPop) {
            showPicker();
        }
    }

    private boolean isCacheCountryList = false;

    private void getCountry(final boolean isShowPop) {
        Map<String, String> params = new HashMap<>();
        params.put("clientType", HostConstant.CLIENT_TYPE);//客户端类型
        OkGo.<String>post(HostConstant.QUERY_TAX_COUNTRY)
                .tag(this)
                .cacheKey(AESUtils.encrypt("isCacheCountryList", HostConstant.QUERY_TAX_COUNTRY))
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .upJson(new Gson().toJson(HttpUtils.getCommonParams(this, params)))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        parseCountryJson(response.body(), isShowPop);
                    }

                    @Override
                    public void onCacheSuccess(Response<String> response) {
                        super.onCacheSuccess(response);
                        if (!isCacheCountryList) {
                            onSuccess(response);
                            isCacheCountryList = true;
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    private void getTaxType(final boolean isOnCreate) {
        Map<String, String> params = new HashMap<>();
        params.put("clientType", HostConstant.CLIENT_TYPE);//客户端类型
        OkGo.<String>post(HostConstant.QUERY_TAXTYPE)
                .tag(this)
                .upJson(new Gson().toJson(HttpUtils.getCommonParams(this, params)))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        parseTaxTypeJson(response.body(), isOnCreate);
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    /**
     * 查询涉税的省
     *
     * @param isShowPop
     */
    private void getTaxProvince(final boolean isShowPop) {
        OkGo.<String>post(HostConstant.QUERY_TAX_PROVINCE)
                .tag(this)
                .upJson(new Gson().toJson(HttpUtils.getCommonParams(this, null)))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        UpdateTaxProvince(response.body(), isShowPop);
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    private void UpdateTaxProvince(String json, boolean isShowPop) {
        QueryTaxProvinceCityBean bean;
        try {
            bean = new Gson().fromJson(json, QueryTaxProvinceCityBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        list.clear();
        taxProvinceList.clear();
        taxProvinceList.addAll(bean.getData());

        if (!isBindLiveProvince && !StringUtils.isNullOrEmpty(liveAddressProvinceCode)) {
            isBindLiveProvince = true;
            String name = getProvinceName(liveAddressProvinceCode);
            tv_tax_live_address_province.setText(name);
        }
        if (!isBindBirthProvince && !StringUtils.isNullOrEmpty(birthAddressProvinceCode)) {
            isBindBirthProvince = true;
            String name = getProvinceName(birthAddressProvinceCode);
            tv_tax_birthplace_address_province.setText(name);
        }
        initPopList();
        if (isShowPop) {
            showPicker();
        }
    }

    /**
     * 查询涉税的市
     *
     * @param queryType
     * @param isShowPop
     */
    private void getTaxCity(final int queryType, String provinceCode, final boolean isShowPop) {
        Map<String, String> params = new HashMap<>();
        if (queryType == 0 || queryType == 3 || queryType == 4) {
            if (StringUtils.isNullOrEmpty(provinceCode)) {
                return;
            }
            params.put("provinceCode", provinceCode);
        }
        OkGo.<String>post(HostConstant.QUERY_TAX_CITY)
                .tag(this)
                .upJson(new Gson().toJson(HttpUtils.getCommonParams(this, params)))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        UpdateTaxCity(response.body(), queryType, isShowPop);
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    private void UpdateTaxCity(String json, int queryType, boolean isShowPop) {
        QueryTaxProvinceCityBean bean;
        try {
            bean = new Gson().fromJson(json, QueryTaxProvinceCityBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        list.clear();
        taxCityList.clear();
        taxCityList.addAll(bean.getData());
        switch (queryType) {
            case 3://说明刚进入页面 绑定用户数据信息时查询的市区列表
                if (!StringUtils.isNullOrEmpty(liveAddressCityCode)) {
                    for (QueryTaxProvinceCityBean.DataBean beanCity : taxCityList) {
                        if (liveAddressCityCode.equals(beanCity.getRegionCode())) {
                            tv_tax_live_address_city.setText(beanCity.getRegionNameCn());//市名称
                            break;
                        }
                    }
                }
                break;
            case 4://说明刚进入页面 绑定用户数据信息时查询的市区列表
                if (!StringUtils.isNullOrEmpty(birthAddressCityCode)) {
                    for (QueryTaxProvinceCityBean.DataBean beanCity : taxCityList) {
                        if (birthAddressCityCode.equals(beanCity.getRegionCode())) {
                            tv_tax_birthplace_address_city.setText(beanCity.getRegionNameCn());//市名称
                            break;
                        }
                    }
                }
                break;
        }
        initPopList();
        if (isShowPop) {
            showPicker();
        }
    }

    private void parseCountryJson(String json, boolean isShowPop) {
        countryList.clear();
        list.clear();
//
        QueryCountryBean bean;
        try {
            bean = new Gson().fromJson(json, QueryCountryBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (TextUtils.isEmpty(json) && !CommonUtil.isNetWorkConnected(mActivity)) {
            showToast(MentorConst.NO_NETWORK_TIP);
            return;
        }

        if (bean == null
                || TextUtils.isEmpty(bean.getErrorCode())) {
            showToast(MentorConst.SERVER_BUSY_TIP);
            return;
        }

        BaseBean baseBean = new BaseBean();
        baseBean.setRespCode(bean.getErrorCode());
        baseBean.setRespMsg(bean.getErrorMessage());
        if (!CommonUtil.checkState(mActivity, baseBean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }
        countryList.addAll(bean.getData());
        ParamUtil.setCountryList(countryList);
        if (!isBindLiveCountryType && !StringUtils.isNullOrEmpty(liveAddressCountryId)) {
            isBindLiveCountryType = true;
            String liveCountryName = getCountryName(liveAddressCountryId);
            tv_tax_live_address_country.setText(liveCountryName);
        }

        if (!isBindBirthCountryType && !StringUtils.isNullOrEmpty(birthAddressCountryId)) {
            isBindBirthCountryType = true;
            String birthCountryName = getCountryName(birthAddressCountryId);
            tv_tax_birthplace_address_country.setText(birthCountryName);
        }
        initPopList();
        if (isShowPop) {
            showPicker();
        }
    }

    private void parseTaxTypeJson(String json, boolean isOnCreate) {
        taxTypeList.clear();
        list.clear();
//
        QueryCountryBean bean;
        try {
            bean = new Gson().fromJson(json, QueryCountryBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (TextUtils.isEmpty(json) && !CommonUtil.isNetWorkConnected(mActivity)) {
            showToast(MentorConst.NO_NETWORK_TIP);
            return;
        }

        if (bean == null
                || TextUtils.isEmpty(bean.getErrorCode())) {
            showToast(MentorConst.SERVER_BUSY_TIP);
            return;
        }

        BaseBean baseBean = new BaseBean();
        baseBean.setRespCode(bean.getErrorCode());
        baseBean.setRespMsg(bean.getErrorMessage());
        if (!CommonUtil.checkState(mActivity, baseBean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        taxTypeList.addAll(bean.getData());
        for (int i = 0; i < taxTypeList.size(); i++) {
            if ("NO".equals(taxTypeList.get(i).getItemValue())) {
                taxTypeList.remove(i);
                break;
            }
        }
//        if (isOnCreate) {
//            if (StringUtils.isNullOrEmpty(identStatement)) {
//                for (int i = 0; i < taxTypeList.size(); i++) {
//                    if ("ON".equals(taxTypeList.get(i).getItemValue())) {
//                        tv_register_step_2_identity_statement.setText(taxTypeList.get(i).getItemName());
//                        identStatement = taxTypeList.get(i).getItemValue();
//                        taxLayoutShow(identStatement);
//                        break;
//                    }
//                }
//            } else {
//                if (!isBindIdentityType) {
//                    for (QueryCountryBean.DataBean data : taxTypeList) {
//                        if (data.getItemValue().equals(identStatement)) {
//                            isBindIdentityType = true;
//                            tv_register_step_2_identity_statement.setText(data.getItemName());
//                        }
//                    }
//                }
//            }
//        }
        initPopList();
        if (identity_statementPopShow) {
            showPicker();
        }
    }

    private String getSelectProvinceCode(String countryId, int selectPosition) {
        if (ParamUtil.isSelectTaxCountry(countryId)) {
            return taxProvinceList.get(selectPosition).getRegionCode();
        }
        return "";
    }

    private class FooterViewClickListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.btn_register_step_2:
                    if (!lastStepCheckData()) {
                        return;
                    }
                    if (accountLoginData.isVerifiedResult()) {
                        saveData();
                    } else {
                        showDialogType = 1;
                        showConfirmAlert(UserInfoEditActivity.this, "温馨提示", accountLoginData.getVerifiedMessage(), "以后再说", "去上传");
                    }
                    break;
                case R.id.tv_other_taxpayer: //其他纳税人,增加条目
                    if (taxPayersContainer != null && Math.min(taxPayersContainer.size(), maxTaxpayerSize) < maxTaxpayerSize) {
                        taxPayerAdapter.addData(taxPayerAdapter.getData().size());
                        taxPayersTotal.clear();
                        taxPayersTotal.addAll(taxPayerAdapter.getData());
                    } else {
                        showToast("超出可添加纳税人数量!");
                    }
                    break;
            }
        }
    }

    private boolean lastStepCheckData() {
        activity_user_info_edit_root.setFocusable(true);
        activity_user_info_edit_root.setFocusableInTouchMode(true);
        sZipCode = et_zip_code.getText().toString().trim();
        sEmail = et_email.getText().toString();
        sAddress = et_address.getText().toString();
        //3.0.7新增 start
        // 职务
        occupation = et_user_info_duty.getText().toString().trim();
        // 账户控制
        controllerName = et_others_control_name.getText().toString().trim();
        controllerCertNo = et_control_identity.getText().toString().trim();
        controllerCertValidTerm = tv_control_identity_validity.getText().toString().trim();
        controllerInstruction = et_control_cause.getText().toString().trim();
        //实际受益人
        beneficiaryName = et_beneficial_owner_name.getText().toString().trim();
        beneficiaryCertNo = et_beneficial_owner_identity.getText().toString().trim();
        beneficiaryCertValidTerm = tv_beneficial_identity_validity.getText().toString().trim();
        beneficiaryInstruction = et_beneficial_owner_cause.getText().toString().trim();

        //不良记录
        badCreditRecords = et_bad_record.getText().toString().trim();
        //3.0.7新增 end

        if (!cbox_certificates_validity.isChecked() &&
                checkParam(tv_certificates_validity.getText().toString(), "请选择证件有效期")) {
            return false;
        }
        if (checkParam(sEmail, "请填写Email")) {
            et_email.setIsSelected(true);
            return false;
        } else {
            if (!StringUtils.isEmail(et_email.getText().toString().trim())) {
                et_email.setIsSelected(true);
                showConfirmAlert(UserInfoEditActivity.this, "邮箱格式不正确");
                return false;
            }
        }

        if (checkParam(profession, "请选择您的职业") || checkParam(tv_occupation_name.getText().toString(), "请选择您的职业")) {//tv_occupation_name
            return false;
        }
        if (checkParam(occupation, "请输入您的职务")) {
            et_user_info_duty.setIsSelected(true);
            return false;
        }

        if (!StringUtils.isNullOrEmpty(sAddress)) {
            if (sAddress.length() < 8) {
                showConfirmAlert(UserInfoEditActivity.this,
                        getResources().getString(R.string.string_register_step2_address_match1));
                et_address.setIsSelected(true);
                et_address.setText("");
                return false;
            } else if (!StringUtils.isContainChinese(sAddress)) {
                showConfirmAlert(UserInfoEditActivity.this,
                        getResources().getString(R.string.string_register_step2_address_match2));
                et_address.setIsSelected(true);
                et_address.setText("");
                return false;
            }
        }

        if (checkParam(sZipCode, "请填写邮编")) {
            et_zip_code.setIsSelected(true);
            return false;
        } else {
            if ((sZipCode.length() != 6)) {
                et_zip_code.setIsSelected(true);
                showConfirmAlert(mActivity, "邮编不合法");
                return false;
            }
        }
        //3.0.7增加 账户他人控制
        if (sbtn_is_others_control.isChecked()) {
            if (checkParam(controllerName, "请输入控制人姓名")) {
                et_others_control_name.setIsSelected(true);
                return false;
            }
            if (checkParam(controllerCertType, "请选择控制人证件类型")) {
                return false;
            }
            if (checkParam(controllerCertNo, "请输入控制人证件号")) {
                et_control_identity.setIsSelected(true);
                return false;
            } else {
                if ("0".equals(controllerCertType)) {
                    if (controllerCertNo.length() != 18) {
                        et_control_identity.setIsSelected(true);
                        showConfirmAlert(this, "请输入合规身份证号");
                        return false;
                    }
                }
            }
            if (!cb_control_identity_validity_time.isChecked() && checkParam(controllerCertValidTerm,
                    "请选择控制人证件有效期")) {
                return false;
            }
            if (checkParam(controllerInstruction, "请说明有此控制关系的原因")) {
                et_control_cause.setIsSelected(true);
                return false;
            }
        }
        //3.0.7增加 受益人
        if (!sbtn_is_beneficial_owner.isChecked()) {
            if (checkParam(beneficiaryName, "请输入受益人姓名")) {
                et_beneficial_owner_name.setIsSelected(true);
                return false;
            }
            if (checkParam(beneficiaryCertType, "请选择受益人证件类型")) {
                return false;
            }
            if (checkParam(beneficiaryCertNo, "请输入受益人证件号")) {
                et_beneficial_owner_identity.setIsSelected(true);
                return false;
            } else {
                if ("0".equals(beneficiaryCertType)) {
                    if (beneficiaryCertNo.length() != 18) {
                        et_beneficial_owner_identity.setIsSelected(true);
                        showConfirmAlert(this, "请输入合规身份证号");
                        return false;
                    }
                }
            }
            if (!cb_beneficial_identity_validity_time.isChecked() && checkParam(beneficiaryCertValidTerm,
                    "请选择受益人证件有效期")) {
                return false;
            }
            if (checkParam(beneficiaryInstruction, "请说明受益人不是本人的原因")) {
                et_beneficial_owner_cause.setIsSelected(true);
                return false;
            }
        }

        //3.0.7新增不良记录
        if (sbtn_is_bad_record.isChecked()) {
            if (checkParam(badCreditRecords, "请输入不良记录内容")) {
                et_bad_record.setIsSelected(true);
                return false;
            }
        }
        if (!paramsCheckTax()) {
            return false;
        }
        return true;
    }

    private void saveData() {
        paramsModifyUserInfo = new HashMap<>();
        paramsModifyUserInfo.put("token", mentorApplication.userBean.getToken());
        paramsModifyUserInfo.put("fundCustomerNo", mentorApplication.userBean.getFundCustomerNo());
        paramsModifyUserInfo.put("certificateValidEver", cbox_certificates_validity.isChecked() ? "1" : "0");// 是否长期有效 1,长期有效 0,不是长期有效
        if (cbox_certificates_validity.isChecked()) {
            paramsModifyUserInfo.put("certificateValidTerm", "");// 证件有效期 非长期有效状况必传
        } else {
            paramsModifyUserInfo.put("certificateValidTerm", tv_certificates_validity.getText().toString().replace("-", ""));// 证件有效期 非长期有效状况必传
        }

        String realNamePri = userBeanTax.getData().getRealName();// 姓名
        if (StringUtils.isNullOrEmpty(realNamePri)) {
            realNamePri = "";
        }
        paramsModifyUserInfo.put("name", realNamePri);// 姓名

        if (!StringUtils.isNullOrEmpty(userBeanTax.getData().getBirthday())) {
            paramsModifyUserInfo.put("birthday", userBeanTax.getData().getBirthday().replace("-", ""));// 出生日期
        }
        paramsModifyUserInfo.put("email", sEmail);// 邮箱
        paramsModifyUserInfo.put("professionCode", profession);// 职业代码
        //3.0.7新增 职务
        paramsModifyUserInfo.put("occupation", occupation);
        paramsModifyUserInfo.put("contactAddress", sAddress);// 联系地址
        paramsModifyUserInfo.put("postCode", sZipCode);// 邮政编码
        //3.0.7新增 账户控制人
        String IsExistActualControl = sbtn_is_others_control.isChecked() ? "1" : "0";
        String controllerCertValidEver = cb_control_identity_validity_time.isChecked() ? "1" : "0";
        paramsModifyUserInfo.put("isExistActualControl", IsExistActualControl);
        if ("1".equals(IsExistActualControl)) {
            paramsModifyUserInfo.put("controllerName", controllerName);
            paramsModifyUserInfo.put("controllerCertType", controllerCertType);
            paramsModifyUserInfo.put("controllerCertNo", controllerCertNo);
            paramsModifyUserInfo.put("controllerCertValidTerm", controllerCertValidTerm);
            paramsModifyUserInfo.put("controllerInstruction", controllerInstruction);
            paramsModifyUserInfo.put("controllerCertValidEver", controllerCertValidEver);
        }
        //3.0.7新增 实际受益人
        String ActualBeneficiaryRelation = sbtn_is_beneficial_owner.isChecked() ? "0" : "1";
        String beneficiaryCertValidEver = cb_beneficial_identity_validity_time.isChecked() ? "1" : "0";
        paramsModifyUserInfo.put("actualBeneficiaryRelation", ActualBeneficiaryRelation);
        if ("1".equals(ActualBeneficiaryRelation)) {
            paramsModifyUserInfo.put("beneficiaryName", beneficiaryName);
            paramsModifyUserInfo.put("beneficiaryCertType", beneficiaryCertType);
            paramsModifyUserInfo.put("beneficiaryCertNo", beneficiaryCertNo);
            paramsModifyUserInfo.put("beneficiaryCertValidTerm", beneficiaryCertValidTerm);
            paramsModifyUserInfo.put("beneficiaryCertValidEver", beneficiaryCertValidEver);
            paramsModifyUserInfo.put("beneficiaryInstruction", beneficiaryInstruction);
        }
        //3.0.7新增不良记录
        String hasBadCreditRecords = sbtn_is_bad_record.isChecked() ? "1" : "0";
        paramsModifyUserInfo.put("hasBadCreditRecords", hasBadCreditRecords);
        if ("1".equals(hasBadCreditRecords)) {
            paramsModifyUserInfo.put("badCreditRecords", badCreditRecords);
        }
        bindTaxParamsData(paramsModifyUserInfo);
        OkGo.<String>post(HostConstant.MODIFY_USERINFO)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, paramsModifyUserInfo))
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        updateUserInfo(response.body());
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    /**
     * 绑定涉税数据 -保存上传参数
     */
    private void bindTaxParamsData(Map<String, String> params) {
        if (params == null || userBeanTax == null || userBeanTax.getData() == null ||
                "8".equals(userBeanTax.getData().getIdentityType()) ||
                "9".equals(userBeanTax.getData().getIdentityType()) ||
                "2".equals(userBeanTax.getData().getIdentityType())) {
            return;
        }

        params.put("taxType", identStatement);

        if ("ON".equals(identStatement)) {
            return;
        }
        //税收居民信息
        params.put("nameEn", et_tax_name.getText().toString());//名
        params.put("surnameEn", et_tax_surname.getText().toString());//姓
        //现居住地详细地址
        params.put("domicileCountryCn", liveAddressCountryId);//居住地-国家
        if (ParamUtil.isSelectTaxCountry(liveAddressCountryId)) {
            params.put("domicileProvinceCn", liveAddressProvinceCode);//居住地-省份
            params.put("domicileCityCn", liveAddressCityCode);//居住地-城市
            params.put("domicileLocationCn", et_tax_live_chinese_address.getText().toString()); //中文地址
            params.put("domicileLocationEn", et_tax_live_pinyin_address.getText().toString());//居住地-地址-拼音
        } else {
            params.put("domicileProvinceCn", hwet_tax_live_address_province.getText().toString());//居住地-省份文
            params.put("domicileCityCn", hwet_tax_live_address_city.getText().toString());//居住地-城市
            params.put("domicileLocationEn", et_tax_live_english_address.getText().toString());//居住地-地址-英文
        }
        //出生地详细地址
        params.put("birthplaceCountryCn", birthAddressCountryId);//出生地-国家-中文
        if (ParamUtil.isSelectTaxCountry(birthAddressCountryId)) {
            params.put("birthplaceProvinceCn", birthAddressProvinceCode);//出生地-省份
            params.put("birthplaceCityCn", birthAddressCityCode);//出生地-城市
        } else {
            params.put("birthplaceProvinceCn", hwet_tax_birthplace_address_province.getText().toString());//出生地-省份
            params.put("birthplaceCityCn", hwet_tax_birthplace_address_city.getText().toString());//出生地-城市
        }
        //  添加是否纳税人识别号参数
        params.put("taxTaxpayernoInfoRequest", new Gson().toJson(ParamUtil.formatTaxPayList(taxPayersTotal)));
        MentorLogger.Loge("个人资料", new Gson().toJson(ParamUtil.formatTaxPayList(taxPayersTotal)));

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == HostConstant.STRAT_UPLOAD_ID) {
            if (data != null) {
                String id_time = data.getStringExtra("id_time");
                if (!StringUtils.isNullOrEmpty(id_time)) {
                    if (id_time.contains("长期")) {
                        id_time = "";
                        cbox_certificates_validity.setChecked(true);
                    } else {
                        cbox_certificates_validity.setChecked(false);
                    }
                    tv_certificates_validity.setText(id_time);
                }
            }
        }
    }
}
